import time
import threading
import sys,socket

 
def callback_func():
    pass
    #print('超时回调')

 
def time_out(interval, callback=None):
    def decorator(func):
        def wrapper(*args, **kwargs):
            t =threading.Thread(target=func, args=args, kwargs=kwargs)
            t.setDaemon(True)  # 设置主线程技术子线程立刻结束
            t.start()
            t.join(interval)  # 主线程阻塞等待interval秒
            if t.is_alive() and callback:
                return threading.Timer(0, callback).start()  # 立即执行回调函数
            else:
                return
        return wrapper
    return decorator

 

        
@time_out(0.1, callback_func)
def hostname(ip):
    try:
        result=socket.gethostbyaddr(ip)
        #print(result[0])
        y=str(result[0])
        names.append(y)
        return y
    except:
        return 0
    
 
if __name__ == '__main__':
    names=[]
    for i in range(60,255):
        ip='10.102.10.'+str(i)
        hostname(ip)
        
        
    print(names)
